package com.stylefeng.guns.modular.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.MyGpcHistory;
import com.stylefeng.guns.modular.system.service.IMyGpcHistoryService;
import com.stylefeng.guns.modular.system.warpper.MyGpcHistoryWarpper;

/**
 * 我的持仓记录控制器
 *
 * @author fengshuonan
 * @Date 2018-07-13 22:22:19
 */
@Controller
@RequestMapping("/myGpcHistory")
public class MyGpcHistoryController extends BaseController {

    private String PREFIX = "/system/myGpcHistory/";

    @Autowired
    private IMyGpcHistoryService myGpcHistoryService;

    /**
     * 跳转到我的持仓记录首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "myGpcHistory.html";
    }

    /**
     * 跳转到添加我的持仓记录
     */
    @RequestMapping("/myGpcHistory_add")
    public String myGpcHistoryAdd() {
        return PREFIX + "myGpcHistory_add.html";
    }

    /**
     * 跳转到修改我的持仓记录
     */
    @RequestMapping("/myGpcHistory_update/{myGpcHistoryId}")
    public String myGpcHistoryUpdate(@PathVariable Integer myGpcHistoryId, Model model) {
        MyGpcHistory myGpcHistory = myGpcHistoryService.selectById(myGpcHistoryId);
        model.addAttribute("item",myGpcHistory);
        LogObjectHolder.me().set(myGpcHistory);
        return PREFIX + "myGpcHistory_edit.html";
    }

    /**
     * 获取我的持仓记录列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String date,String dm) {
    	Page<MyGpcHistory> page = new PageFactory<MyGpcHistory>().defaultPage();
    	List<Map<String, Object>> gdhs = myGpcHistoryService.selectMapsByDm(page,date,dm);
    	page.setRecords((List<MyGpcHistory>) new MyGpcHistoryWarpper(gdhs).warp());
        return super.packForBT(page);
    }

    /**
     * 新增我的持仓记录
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(MyGpcHistory myGpcHistory) {
        myGpcHistoryService.insert(myGpcHistory);
        return SUCCESS_TIP;
    }

    /**
     * 删除我的持仓记录
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer myGpcHistoryId) {
        myGpcHistoryService.deleteById(myGpcHistoryId);
        return SUCCESS_TIP;
    }

    /**
     * 修改我的持仓记录
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(MyGpcHistory myGpcHistory) {
        myGpcHistoryService.updateById(myGpcHistory);
        return SUCCESS_TIP;
    }

    /**
     * 我的持仓记录详情
     */
    @RequestMapping(value = "/detail/{myGpcHistoryId}")
    @ResponseBody
    public Object detail(@PathVariable("myGpcHistoryId") Integer myGpcHistoryId) {
        return myGpcHistoryService.selectById(myGpcHistoryId);
    }
}
